package com.luyou.a06;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;

/**
 * @author 28336
 * @version 1.0
 * Create by 2023/12/20 20:13
 */
@Slf4j
public class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean {

    @Override
    public void setBeanName(String name) {
        log.info("当前 Bean:{} 名字叫:{}", this, name );
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info("当前 Bean:{} 容器是:{}", this ,applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("当前 Bean:{} 初始化", this);
    }

    @Autowired
    public void setApplicationContextWithAutowired(ApplicationContext applicationContext) {
        log.info("当前 Bean: " + this + " 使用 @Autowired 注解，容器是: " + applicationContext);
    }

    @PostConstruct
    public void init() {
        log.info("当前 Bean: " + this + " 使用 @PostConstruct 注解初始化");
    }
}
